package com.ycsj.goldmedalnewconcept.activity;

import java.io.IOException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.google.gson.Gson;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.picasso.Picasso;
import com.ycsj.goldmedalnewconcept.activity.GonggaoActivity.GongaoInfoAdapter;
import com.ycsj.goldmedalnewconcept.activity.GonggaoActivity.GongaoInfoAdapter.ViewHolder;
import com.ycsj.goldmedalnewconcept.bean.GonggaoInfo;
import com.ycsj.goldmedalnewconcept.bean.GonggaoResponse;
import com.ycsj.goldmedalnewconcept.constant.Constant;
import com.ycsj.goldmedalnewconcept.utils.Bimp;
import com.ycsj.goldmedalnewconcept.utils.SPUtil;
import com.ycsj.goldmedalnewconcept.R;

//公告详情
public class GonggaoPreviewActivity extends Activity implements OnClickListener {

	private ImageView iv_back;
	private Intent intent;
	private ListView lv_gonggao;
	private int position;
	private String role;
	private String account;
	private String type;
	private String theme;
	private String content;
	private GongaoInfoAdapter mAdapter;
	private List<GonggaoInfo> gonggaolist;
	private List<String> imglist;
	private TextView tv_title;
	private TextView tv_time;
	private TextView tv_content;
	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	Date curDate = new Date(System.currentTimeMillis());

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gonggaopreview);
		role = SPUtil.getString(this, "role", "");
		account = SPUtil.getString(this, "account", "");

		intent = getIntent();
		theme = intent.getStringExtra("theme");
		content = intent.getStringExtra("content");
		Log.e("test", theme);
		Log.e("test", content);
		initView();
		setOnListener();
		initData();
	}

	private void initView() {
		// TODO Auto-generated method stub
		iv_back = (ImageView) findViewById(R.id.iv_back);
		lv_gonggao = (ListView) findViewById(R.id.lv_gonggao);
		// iv_img = (ImageView) findViewById(R.id.iv_img);
		// tv_theme = (TextView) findViewById(R.id.tv_theme);
		// tv_content = (TextView) findViewById(R.id.tv_content);
		// tv_date = (TextView) findViewById(R.id.tv_date);
		// tv_address = (TextView) findViewById(R.id.tv_address);

		View headerView = LayoutInflater.from(getBaseContext()).inflate(
				R.layout.gonggaodetail_header, null);
		tv_title = (TextView) headerView.findViewById(R.id.tv_title);
		tv_time = (TextView) headerView.findViewById(R.id.tv_time);
		tv_content = (TextView) headerView.findViewById(R.id.tv_content);

		lv_gonggao.addHeaderView(headerView);
	}

	private void initData() {

		mAdapter = new GongaoInfoAdapter();
		tv_title.setText(theme);

		String str = formatter.format(curDate);
		tv_time.setText(str);
		tv_content.setText(content);

		lv_gonggao.setAdapter(mAdapter);

		

	}

	private void setOnListener() {
		// TODO Auto-generated method stub
		iv_back.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.iv_back:
			finish();
			break;

		}
	}

	class GongaoInfoAdapter extends BaseAdapter {

		public int getCount() {

			return Bimp.tempSelectBitmap.size();
		}

		public Object getItem(int position) {

			return null;
		}

		public long getItemId(int position) {

			return 0;
		}

		ViewHolder vh = null;

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			if (convertView == null) {
				convertView = View.inflate(parent.getContext(),
						R.layout.item_gonggaodetail, null);
				vh = new ViewHolder();

				vh.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);

				convertView.setTag(vh);
			} else {
				vh = (ViewHolder) convertView.getTag();
			}

			// if(gonggaolist.get(position).user_picture1!=null){
			//
			// Picasso.with(GonggaoActivity.this)
			// .load(gonggaolist.get(position).user_picture1).into(vh.iv_img);
			// }else{
			// vh.iv_img.setVisibility(vh.iv_img.GONE);
			// }

			vh.iv_img.setImageBitmap(Bimp.tempSelectBitmap.get(position)
					.getBitmap());

			return convertView;
		}

		class ViewHolder {
			private ImageView iv_img;

		}
	}

}
